import { _decorator, Component, Node, Label, Vec3, UITransform, Size, Widget } from "cc";
const { ccclass, property } = _decorator;

@ccclass("UserInfo")
export class UserInfo extends Component {
    @property(Node)
    private nickNameBox: Node = null;
    @property(Label)
    private nickNameLabel: Label = null;
    @property(Node)
    private talkNode: Node = null;
    @property(Label)
    private talkLabel: Label = null;

    public userId = "";
    public nickName = "";

    init(data, isMe) {
        console.log("UserInfo init", data, isMe);
        this.userId = data.userId;
        this.nickName = data.nickName;

        if (isMe) {
            this.nickNameBox.active = false;
            this.talkNode.getComponent(Widget).bottom = 0;
        }
        this.nickNameLabel.string = this.nickName;
    }

    sync(pos: Vec3) {
        this.node.setPosition(pos);
    }

    talk(str) {
        this.unscheduleAllCallbacks();
        this.talkNode.active = true;
        this.talkLabel.string = str;

        this.scheduleOnce(() => {
            this.talkNode.active = false;
        }, 2);
    }
}
